package com.bindatax.biz.etl;

import com.bindatax.core.config.SysConfig;
import com.bindatax.core.custom.GlobalConstant;
import com.bindatax.core.dspool.DataTaskConnManager;
import com.bindatax.core.log.LogOutManager;
import com.bindatax.core.meta.TaskMeta;
import com.bindatax.core.task.DataTask;
import com.bindatax.core.task.DataTaskPool;
import com.bindatax.core.task.spi.TaskSpiManager;
import com.bindatax.core.util.PropertiesUtil;

import java.util.Properties;

public class BinDataxBoot {

   public static DataTaskPool init(Properties sysPros,Properties logPros,Properties dsPoolPros){
      SysConfig.readPros(sysPros);
      LogOutManager.initLog(logPros,SysConfig.getLogSystemType());//初始化日志系统
      DataTaskConnManager.init(dsPoolPros);//初始化任务连接池
      TaskSpiManager.init();//初始化任务事件管理
      DataTaskPool dataTaskPool = new DataTaskPool();
      return dataTaskPool;
   }

   public static void addTask(DataTaskPool dataTaskPool ,Properties taskMetaPros,Object parent) {
      TaskMeta taskMeta = new TaskMeta(taskMetaPros);
      DataTask dataTask = new DataTask(taskMeta,parent);
      dataTaskPool.addDataTask(dataTask);
   }

   public static void start(String configPath,Object parent){
      // 分别加载四个配置文件对象
      String TASK_DS_POOL_FILE_NAME = configPath +"/"+ GlobalConstant.TASK_DS_POOL_FILE_NAME;//线程池配置文件
      String TASK_LOG_FILE_NAME = configPath +"/"+ GlobalConstant.TASK_LOG_FILE_NAME;//日志属性配置文件
      String TASK_META_FILE_NAME = configPath +"/"+ GlobalConstant.TASK_META_FILE_NAME;//任务元数据配置文件
      String TASK_SYS_FILE_NAME= configPath +"/"+ GlobalConstant.TASK_SYS_FILE_NAME;//任务系统配置文件

      Properties sysPros = PropertiesUtil.read(TASK_SYS_FILE_NAME);
      Properties dsPoolPros = PropertiesUtil.read(TASK_DS_POOL_FILE_NAME);
      Properties logPros = PropertiesUtil.read(TASK_LOG_FILE_NAME);
      Properties taskMetaPros = PropertiesUtil.read(TASK_META_FILE_NAME);

      SysConfig.readPros(sysPros);
      LogOutManager.initLog(logPros,SysConfig.getLogSystemType());//初始化日志系统
      DataTaskConnManager.init(dsPoolPros);//初始化任务连接池
      TaskSpiManager.init();//初始化任务事件管理

      DataTaskPool dataTaskPool = new DataTaskPool();
      TaskMeta taskMeta = new TaskMeta(taskMetaPros);
      taskMeta.addBizValue("xzqhdm","123456");
      taskMeta.addBizValue("xzqhmc","xzqhmc");
      taskMeta.addBizValue("group","no.1");
      taskMeta.addBizValue("remarks","测试入库多线程程序");
      DataTask dataTask = new DataTask(taskMeta,parent);
      dataTaskPool.addDataTask(dataTask);
      dataTaskPool.waitDataTaskFinished();
   }

}
